package com.csg.service.service.impl;

import com.csg.service.entity.Client;
import com.csg.service.entity.Role;
import com.csg.service.service.ClientService;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
 * @author george
 */
@Slf4j
@Service(value = "clientService")
public class ClientServiceImpl implements ClientService {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public ClientDetails loadClientByClientId(String clientId) {
        log.info("客户端的账号：" + clientId);
        String clientSecret = passwordEncoder.encode("123456");
        log.info("客户端的密码：" + clientSecret);
        String scope = "all";
        String resourceIds = "";
        String authorizedGrantTypes = "authorization_code, password, client_credentials, implicit, refresh_token";
        String registeredRedirectUris = "www.baidu.com";
        String autoApproveScopes = "";
        Set<Role> roles = Sets.newHashSet();
        roles.add(new Role("ROLE_USER"));
        Integer accessTokenValiditySeconds = 3000;
        Integer refreshTokenValiditySeconds = 3000;
        return new Client(clientId, clientSecret, scope, resourceIds, authorizedGrantTypes, registeredRedirectUris, autoApproveScopes, roles, accessTokenValiditySeconds, refreshTokenValiditySeconds);
    }
}
